package mark;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ScrollView;
import android.widget.Toast;
import com.zyyoona7.lib.EasyPopup;
import com.zyyoona7.lib.HorizontalGravity;
import com.zyyoona7.lib.VerticalGravity;
import org.jaaksi.commondemo.R;

/**
 * 创建时间：2018年02月08日15:39 <br>
 * 作者：fuchaoyang <br>
 * 描述：
 */

public class TestMarkActivity extends AppCompatActivity /*implements View.OnScrollChangeListener*/ {
  EasyPopup mPopup;
  View attachview;
  private StickyMark mStickyMark;

  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_testmark);
    attachview = findViewById(R.id.attachview);
    ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView);
    //scrollView.setOnScrollChangeListener(this); // 23
    initPop();
    attachview.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        Toast.makeText(TestMarkActivity.this, "ok", 1).show();
      }
    });
    //mStickyMark = new StickyMark(this);
    //mStickyMark.setMarkView(getLayoutInflater().inflate(R.layout.popup_mark, null));
    mPopup.setAnchorView(attachview);
  }

  private void initPop() {
    if (mPopup == null) {
      mPopup =
          new EasyPopup(this).setContentView(R.layout.popup_mark).setFocusAndOutsideEnable(false)
              //.setBackgroundDimEnable(true)
              .setDimValue(0.5f).setDimColor(Color.TRANSPARENT).createPopup();
      View contentView = mPopup.getContentView();
    }
  }

  private void attach(View v) {
    mPopup.showAtAnchorView(v, VerticalGravity.BELOW, HorizontalGravity.RIGHT, 0, 0);
  }

  @Override
  public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
    mStickyMark.attach(attachview);
  }
}
